package ncit.bluetooth.settings;

import java.util.HashMap;
import ncit.bluetooth.control.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AdvanceSettingsParani extends Activity implements OnClickListener{

	//DEBUG info
	private static final String TAG = "bluetooth.settings.AdvanceSettingsParani";
	
	@Override
	public void onCreate(Bundle savedInstanceState){

		super.onCreate(savedInstanceState);
		setContentView(R.layout.parani_adv_settings);

		Button saveButton = (Button)findViewById(R.id.save_parani_settings_button);
		saveButton.setOnClickListener(this);

		HashMap<String, String> stringSettings = BluetoothControlSettings.stringSettings;

		Log.d(TAG, stringSettings.toString());

		//set the text from the EditText Box for the forward command 
		EditText forward_acc_comm = (EditText)findViewById(R.id.forward_acc_comm);
		forward_acc_comm.setText(stringSettings.get("goForwardByte"));

		//set the text from the EditTextBox for the backwards command
		EditText backwards_acc_comm = (EditText)findViewById(R.id.backward_acc_comm);
		backwards_acc_comm.setText(stringSettings.get("goBackwardByte"));

		//set the text from the EditText Box for the left command
		EditText left_acc_comm = (EditText)findViewById(R.id.left_acc_comm);
		left_acc_comm.setText(stringSettings.get("goLeftByte"));

		//set the text from the EditText Box for the right command
		EditText right_acc_comm = (EditText)findViewById(R.id.right_acc_comm);
		right_acc_comm.setText(stringSettings.get("goRightByte"));

		//set the text from the EditText Box for the max power forward
		EditText max_forward_power = (EditText) findViewById(R.id.max_forward_power);
		max_forward_power.setText(stringSettings.get("maxPowerForward"));

		//set the text from the EditText Box for the max power backwards
		EditText max_backwards_power = (EditText) findViewById(R.id.max_backward_power);
		max_backwards_power.setText(stringSettings.get("maxPowerBackwards"));

		//set the text from the EditText Box for the max power left
		EditText max_left_power = (EditText) findViewById(R.id.max_diirection_power);
		max_left_power.setText(stringSettings.get("maxPowerLeft"));

	}

	public void save()
	{
		HashMap<String, String> stringSettings = BluetoothControlSettings.stringSettings;

		//get the text from the EditText Box for the forward command 
		EditText forward_acc_comm = (EditText)findViewById(R.id.forward_acc_comm);
		String s = forward_acc_comm.getText().toString();
		stringSettings.remove("goForwardByte");
		stringSettings.put("goForwardByte",s);

		//get the text from the EditTextBox for the backwards command
		EditText backwards_acc_comm = (EditText)findViewById(R.id.backward_acc_comm);
		s = backwards_acc_comm.getText().toString();
		stringSettings.remove("goBackwardByte");
		stringSettings.put("goBackwardByte",s);

		//get the text from the EditText Box for the left command
		EditText left_acc_comm = (EditText)findViewById(R.id.left_acc_comm);
		s = left_acc_comm.getText().toString();
		stringSettings.remove("goLeftByte");
		stringSettings.put("goLeftByte", s);

		//get the text from the EditText Box for the right command
		EditText right_acc_comm = (EditText)findViewById(R.id.right_acc_comm);
		s = right_acc_comm.getText().toString();
		stringSettings.remove("goRightByte");
		stringSettings.put("goRightByte", s);

		//get the text from the EditText Box for the max power forward
		EditText max_forward_power = (EditText) findViewById(R.id.max_forward_power);
		s = max_forward_power.getText().toString();
		stringSettings.remove("maxPowerForward");
		stringSettings.put("maxPowerForward",s);

		//get the text from the EditText Box for the max power backwards
		EditText max_backwards_power = (EditText) findViewById(R.id.max_backward_power);
		s = max_backwards_power.getText().toString();
		stringSettings.remove("maxPowerBackwards");
		stringSettings.put("maxPowerBackwards", s);

		//get the text from the EditText Box for the max power left
		EditText max_left_power = (EditText) findViewById(R.id.max_diirection_power);
		s = max_left_power.getText().toString();
		stringSettings.remove("maxPowerLeft");
		stringSettings.put("maxPowerLeft", s);
		stringSettings.remove("maxPowerRight");
		stringSettings.put("maxPowerRight", s);
	}

	public void onClick(View v) {

		save();
		finish();

	}


	@Override
	public void onStop()
	{
		super.onStop();
		save();
	}

	@Override
	public void onDestroy()
	{
		super.onDestroy();
		save();
	}


}
